fix time encoding to work with Cassandra 4#269
fix time encoding to work with Cassandra 4#269Roguelazer wants to merge 1 commit intodatastax:masterfrom
Conversation
|
Hey @Roguelazer, thanks (again) for the PR! Do you happen to have some sample code that you can share which exercises this issue? I ask because it looks like you're trying to call Cassandra::Utils.encode_time with a Ruby Time object with the expectation that you'll get something out that can be inserted into a column of timestamp type. The problem is that the driver tries to encode Time objects via encode_timestamp while encode_time is reserved for Cassandra::Time (https://github.com/datastax/ruby-driver/blob/master/lib/cassandra/util.rb#L94-L115). So you wind up with the following behaviour here: Given that a Ruby top-level Time object maps to a "timestamp" CQL type while Cassandra::Time maps to a "time" type I'd expect that given the following: this code should work without issue: And indeed that's exactly what I get; the code runs without an error of any kind and after execution I observe the following: That's with Ruby 2.5.1 (using cassandra-driver 3.2.5) against Cassandra 4.0.0. Please let me know if I've misunderstood something about your use case @Roguelazer. |
The default Ruby
.to_smethod for a Time results in output of%Y-%m-%d %H:%M:%S %z; note the space between the seconds and the time offset.In Cassandra 4.0, the validator for the
TIMESTAMPcolumn type is stricter and there cannot be a space between the fractional part and the timezone offset and it must match the formatyyyy-mm-dd[(T| )HH:MM:SS[.fff]][(+|-)NNNN].